package com.cskaoyan.utils;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @ClassName MyGetCurrentTime
 * @Description
 * @Author Lxz
 * @Date 2022-8-13 12:31
 */
public class MyGetCurrentTime {

    /**
     *  需要在响应的类中对应的Date变量上添加注解
     *  ` @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
     *  e.g. MarketAdmin的addTime成员变量
     * @return java.util.Date
     * @author Lxz
     * @since 2022/08/13 13:48
     */
    public static Date getCurrentTime() {
        LocalDateTime localDateTime = LocalDateTime.now();
        Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
        return date;
    }

    /**
     *  获取string：yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static String getCurrentTimeStr(){
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = sdf.format(date);
        return str;
    }

}
